package com.weipai.education.controller;

import com.weipai.education.model.Document;
import com.weipai.education.model.Picture;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/11 14:19
 */
@RestController
@Validated
public class SystemController {
    
    @Autowired
    private SystemService systemService;

    /**
     * 分页查询--图片
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/system/list", method = RequestMethod.GET)
    public Response pictureList(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                                @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size){
        return systemService.pictureList(page, size);
    }

    /**
     * 图片保存--修改
     * @param picture
     * @return
     */
    @RequestMapping(value = "/system/savePicture", method = RequestMethod.POST)
    public Response savePicture(@Valid Picture picture){
        return systemService.savePicture(picture);
    }

    /**
     * 更改图片状态
     * @param id
     * @return
     */
    @RequestMapping(value = "/system/changeStatus", method = RequestMethod.GET)
    public Response changeStatus(@NotBlank(message = "图片id不能为空") String id){
        return systemService.changeStatus(id);
    }

    /**
     * 图片批量删除
     * @param id:
     * @return
     */
    @RequestMapping(value = "/system/batchDeleteById", method = RequestMethod.GET)
    public Response batchDeleteById(@NotEmpty(message = "图片id不能为空") String[] id){
        return systemService.batchDeleteById(id);
    }

    /**
     * 文本保存--修改
     * @param document
     * @return
     */
    @RequestMapping(value = "/system/saveDocument", method = RequestMethod.POST)
    public Response saveDocument(@Valid Document document){
        return systemService.saveDocument(document);
    }

    /**
     * 获取文本内容
     * @return
     */
    @RequestMapping(value = "/system/getDocument", method = RequestMethod.GET)
    public Response getDocument(){
        return systemService.getDocument();
    }


    /**
     * 获取推送消息
     * @return
     */
    @RequestMapping(value = "/system/getMessageByUserId",method = RequestMethod.POST)
    public Response getMessageByUserId(){
        return systemService.selectAllMessage();
    }

    /**
     * 获取当前用户未读数量
     * @return
     */
    @RequestMapping(value = "/system/getMessageNum",method = RequestMethod.GET)
    public Response getMessageNum(){
        return systemService.getMessageNum();
    }

    @RequestMapping(value = "/system/changeMessageStatus",method = RequestMethod.GET)
    public Response changeMessageStatus(Integer messageId){
        return systemService.changeMessageStatus(messageId);
    }
}
